package com.yykj.backstage.all.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yykj.backstage.all.dto.AdminRoleDTO;
import com.yykj.backstage.all.dto.AdminMenu;
import com.yykj.backstage.all.form.AdminRoleForm;
import com.yykj.backstage.all.form.AdminMenuForm;
import com.yykj.backstage.all.model.entity.AdminOauth;
import com.yykj.backstage.all.service.AdminService;
import com.yykj.common.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/api/backstage/all")
@Api(tags = "总后台权限相关接口")
@SuppressWarnings("unchecked")
public class BackstageOauthController {

    //====================================================================================================

    @ApiOperation("系统菜单--添加")
    @PostMapping("/menu/add")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVO addMenu(@RequestBody AdminMenuForm form){
        return ResultVO.success(adminService.editMenu(form));
    }

    @ApiOperation("系统菜单--修改")
    @PutMapping("/menu/edit")
    public ResultVO<AdminOauth> editMenu(@RequestBody AdminMenuForm form){
        return ResultVO.success(adminService.editMenu(form));
    }

    @ApiOperation("系统菜单-- 删除")
    @DeleteMapping("/menu/delete/{id}")
    public ResultVO deleteMenu(@PathVariable Integer id){
        adminService.deleteMenu(id);
        return ResultVO.success();
    }

    @GetMapping("/menu/admin/{adminId}/menu")
    @ApiOperation("系统菜单--列表")
    public ResultVO<List<AdminMenu>> getAdminMenu(@PathVariable Integer adminId){
        return ResultVO.success(adminService.getAdminMenu(adminId));
    }

    //====================================================================================================


    @ApiOperation("角色--添加")
    @PostMapping("/role/add")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVO<AdminRoleDTO> addRole(@RequestBody AdminRoleForm form){
        return ResultVO.success(adminService.editRole(form));
    }

    @ApiOperation("角色--修改")
    @PutMapping("/role/edit")
    public ResultVO<AdminRoleDTO> editRole(@RequestBody AdminRoleForm form){
        return ResultVO.success(adminService.editRole(form));
    }

    @ApiOperation("角色--删除")
    @DeleteMapping("/role/delete/{groupId}")
    public ResultVO<AdminRoleDTO> deleteRole(@PathVariable Integer groupId){
        adminService.deleteRole(groupId);
        return ResultVO.success();
    }

    @ApiOperation("角色--列表")
    @GetMapping("/role/list")
    public ResultVO<List<AdminRoleDTO>> listRole(){
        return ResultVO.success(adminService.listRole());
    }

    private AdminService adminService;

    @Autowired
    public void setAdminService(AdminService adminService) {
        this.adminService = adminService;
    }

}
